package demoMod.invincibleOne.powers;

import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.powers.NoDrawPower;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.interfaces.IOnCurseAddToHand;

public class CreamyCursePower extends AbstractPower implements IOnCurseAddToHand {
    public static final String POWER_ID = InvincibleOneMod.makeID("CreamyCursePower");
    private static final PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    public static final String NAME = powerStrings.NAME;
    public static final String[] DESC = powerStrings.DESCRIPTIONS;

    private final boolean upgraded;

    public CreamyCursePower(AbstractCreature owner, int amount, boolean upgraded) {
        this.owner = owner;
        this.ID = POWER_ID;
        this.upgraded = upgraded;
        this.name = NAME;
        if (upgraded) {
            this.ID += "+";
            this.name += "+";
        }
        this.amount = amount;
        this.updateDescription();
        loadRegion("painfulStabs");
        this.type = PowerType.DEBUFF;
    }

    @Override
    public void updateDescription() {
        if (upgraded) {
            this.description = String.format(DESC[1], this.amount);
        } else {
            this.description = String.format(DESC[0], this.amount);
        }
    }

    @Override
    public void onCardDraw(AbstractCard card) {
        if ((upgraded && card.type == AbstractCard.CardType.STATUS
            || card.type == AbstractCard.CardType.CURSE
            || card.hasTag(CardTagsEnum.VIRUS))
                && !this.owner.hasPower(NoDrawPower.POWER_ID)) {
            onCurseAddToHand(card);
        }
    }

    @Override
    public void onCurseAddToHand(AbstractCard c) {
        this.flash();
        addToBot(new ApplyPowerAction(owner, owner, new OilStainedPower(owner, this.amount)));
    }
}
